TopologicalSort
TopologicalSort[g] gives a list of vertices of g in topologically sorted order for a directed acyclic graph g.
TopologicalSort[{v->w,…}] uses rules v->w to specify the graph g.
Please visit the official Wolfram Language Reference for more details and examples on core symbols.